//
//  PlayerTeam.m
//  PacIsBack
//
//  Created by Simon André on 28/01/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "PlayerTeam.h"
#import "BattleTeamViewController.h"
#import "CharacterProtocol.h"
#import "Constants.h"


@implementation PlayerTeam

@synthesize characters, controller, currentBattle;

-(id) initWithCharacters:(NSArray*) charactersInBattleTeam{
	if (self = [super init]) {
		[self setCharacters:charactersInBattleTeam];
		for (id<CharacterProtocol> character in [self characters]) {
			[character setManualyPlayed:YES];
			[character setTeam:self];
		}
		BattleTeamViewController* contr = [[BattleTeamViewController alloc] initBattleTeamControllerForModel:self withFrame:CGRectMake(playerTeamPositionX, playerTeamPositionY, playerTeamWidth, playerTeamHeight)];
		[self setController:contr];
		[contr release];
	}
	
	return self;	
}

- (BOOL) isAlive{
	for (id<CharacterProtocol> charact in [self characters]) {
		if ([charact isAlive]) {
			return YES;
		}
	}
	return NO;
}

-(void) obtainVictoryAgainst:(id<BattleTeamProtocol>) defeatedTeam{
	for (id<CharacterProtocol> defeatedCharact in [defeatedTeam characters]) {
		for (id<CharacterProtocol> winningCharact in [self characters]) {
			[winningCharact gainExperience:[defeatedCharact experienceReward]];
		}
	}
}

- (void) dealloc{
	[self setCharacters:nil];
	[self setCurrentBattle:nil];
	[self setController:nil];
	[super dealloc];
}

@end
